package com.zyk.scaffold.user.controller.tenant;


import com.zyk.scaffold.common.basic.BasicConstants;
import com.zyk.scaffold.core.domain.Result;
import com.zyk.scaffold.user.service.TenantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 租户表 前端控制器
 * </p>
 *
 * @author zhouyk
 * @since 2022-11-04
 */
@Api(tags = "租户-API")
@RestController
@RequestMapping("/tenant")
public class TenantController {
    @Autowired
    private TenantService tenantService;

    @ApiOperation("新建租户")
    @PostMapping("/create")
    public Result<Boolean> create(@RequestBody @Validated TenantCreatRequest tenantCreatInput,
                                  @RequestHeader(BasicConstants.HEADER_USER_ID) Long userId){
        return Result.ok(tenantService.create(tenantCreatInput, userId));
    }


    @ApiOperation("修改租户")
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody @Validated TenantUpdateRequest tenantUpdateInput,
                                  @RequestHeader(BasicConstants.HEADER_USER_ID) Long userId){
        return Result.ok(tenantService.update(tenantUpdateInput, userId));
    }


    @ApiOperation("租户列表")
    @PostMapping("/list")
    public Result<List<TenantResponse>> list(){
        return Result.ok(tenantService.listInofs());
    }
}
